package com.yunhui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunhui.entity.RouteIssued;
import com.yunhui.mapper.RouteIssuedMapper;
import com.yunhui.service.RouteIssuedService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  行程的发布业务处理的层实现类
 * </p>
 *
 * @author WGH
 * @since 2019-12-09
 */
@Service
public class RouteIssuedServiceImpl extends ServiceImpl<RouteIssuedMapper, RouteIssued> implements RouteIssuedService {

    @Resource
    private RouteIssuedMapper mapper;

    @Override
    public Integer findCount(String title,Integer mid) {
        return mapper.findCount(title,mid);
    }

    @Override
    public List<RouteIssued> findPage(int Size, int pageIndex, String routeslssued,int mid) {
        int num = (Size-1)*pageIndex;
        return mapper.findPage(num,pageIndex,routeslssued,mid);
    }

    @Override
    public Integer deleteRoutlssuedAndJb(Integer id) {
        return this.mapper.deleteRoutlssuedAndJb(id);
    }

    @Override
    public Integer addRouteIssued(Integer id, Date startTimes, Integer days) {
        return mapper.addRouteIssued(id,startTimes,days);
    }

    @Override
    public List<RouteIssued> selectByJbIdandTime(Integer jbid, Date startTimes) {

        List<RouteIssued> list = null;
        try{

            if(jbid !=null && startTimes!=null){
                String formatDate = null;
                formatDate = DateFormat.getDateInstance().format(startTimes);
              list =  mapper.selectList(new QueryWrapper<RouteIssued>().eq("jbId",jbid).eq("startTimes",formatDate));
            }else {
                list =  mapper.selectList(new QueryWrapper<RouteIssued>().eq("jbId",jbid));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }


    @Override
    public Integer selectByJbId(Integer faid) {
        int num = 0 ;
        try{
            num = mapper.selectByJbId(faid);
        }catch (Exception e){
            e.printStackTrace();
        }
        return  num;
    }

}
